//: io/Blip3.java
package io; /* Added by Eclipse.py */
// Reconstructing an externalizable object.
import java.io.*;
import static net.mindview.util.Print.*;

public class Blip3 implements Serializable {
	private int i;
	private String s; // No initialization
	private Alien alien;
	//private Object obj;

	public Blip3() {
		print("Blip3 Constructor");
		// s, i not initialized
	}

	public Blip3(String x, int a) {
		print("Blip3(String x, int a)");
		s = x;
		i = a;
		alien = new Alien();
		//obj = new Object();
		// s & i initialized only in non-default constructor.
	}

	public String toString() {
		return s +" | "+ i +" | "+ alien +" | "/*+ obj*/;
	}

	//@Override
	public void writeExternal(ObjectOutput out) throws IOException {
		print("Blip3.writeExternal");
		// You must do this:
		out.writeObject(s);
		out.writeInt(i);
		out.writeObject(alien);
		//out.writeObject(obj);  //! java.io.NotSerializableException: java.lang.Object
	}

	//@Override
	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
		print("Blip3.readExternal");
		// You must do this:
		s = (String) in.readObject();
		i = in.readInt();
		alien = (Alien) in.readObject();
		//obj = in.readObject(); 
	}

	public static void main(String[] args) throws IOException, ClassNotFoundException {
		print("Constructing objects:");
		Blip3 b3 = new Blip3("A String ", 47);
		print(b3);
		ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("Blip3.out"));
		print("Saving object:");
		o.writeObject(b3);
		o.close();
		// Now get it back:
		ObjectInputStream in = new ObjectInputStream(new FileInputStream("Blip3.out"));
		print("Recovering b3:");
		b3 = (Blip3) in.readObject();
		print(b3);
		in.close();
	}
} /* Output:
Constructing objects:
Blip3(String x, int a)
A String 47
Saving object:
Blip3.writeExternal
Recovering b3:
Blip3 Constructor
Blip3.readExternal
A String 47
*///:~
